<?php

define('ROOT_DIR',dirname(dirname(__FILE__)));
define('APP_DIR', ROOT_DIR."/application");
define('HELPERS_DIR', ROOT_DIR."/application/helpers");
define('PUBLIC_DIR', ROOT_DIR."/public");
define('APP_ROOT', '');
define('CSS_BASE', APP_ROOT."/css");
define('JS_BASE', APP_ROOT."/js");
define('ART_BASE', APP_ROOT."/art");
define('FD_ART_BASE', ART_BASE."/FD");
define('FH_ART_BASE', ART_BASE."/FH");
define('DOJO_BASE', APP_ROOT."/js/dojo");
define('DIJIT_BASE', APP_ROOT."/js/dijit");
define('DOJOX_BASE', APP_ROOT."/js/dojox");
define('ARTWORK_DIR',PUBLIC_DIR."/art");
define('FD_ARTWORK_DIR', ARTWORK_DIR."/FD");
define('FH_ARTWORK_DIR', ARTWORK_DIR."/FH");
define('KS_ARTWORK_DIR', ARTWORK_DIR."/KSs");
define('FD_ART_INC_DIR', ARTWORK_DIR."/FDs");
define('MERCH_ART_ROOT', APP_ROOT."/art/merch");

class Bootstrap {

	public function __construct( $configSection )
	{
		$paths[] = get_include_path();
		$paths[] = ROOT_DIR.'/library';
		$paths[] = ROOT_DIR.'/application/models/';
		$paths[] = ROOT_DIR.'/application/forms/';
		$paths[] = ROOT_DIR.'/application/helpers/';
		$paths[] = ROOT_DIR.'/application/sandbox/';

		$newpath = implode( $paths, PATH_SEPARATOR );
		set_include_path( $newpath );

		require_once 'Zend/Loader.php';
		Zend_Loader::registerAutoload();

		// load configuration
		Zend_Registry::set('configuration', $configSection);
		$config = new Zend_Config_Ini( ROOT_DIR.'/application/config.ini', $configSection );
		Zend_Registry::set('config', $config);
		date_default_timezone_set($config->date->default_timezone);

		// configure db and store to registry
		$db = Zend_Db::factory($config->db);
		Zend_Db_Table_Abstract::setDefaultAdapter($db);
		Zend_Registry::set('db',$db);
	}

	public function configureFrontController()
	{
		$frontController = Zend_Controller_Front::getInstance();
		$frontController->setControllerDirectory(ROOT_DIR.'/application/controllers');
	}

	public function runApp()
	{
		$this->configureFrontController();
		$frontController = Zend_Controller_Front::getInstance();
		$frontController->throwExceptions(true);

		// set up routes to map to VAS controller
		/*		$router = $frontController->getRouter();
		$vas_intro_route = new Zend_Controller_Router_Route('vas/:method',
		array('controller' => 'vas'));

		$router->addRoute('vas/introduction');*/

		Zend_Session::start();

		Zend_Layout::startMvc(array('layoutPath'=>ROOT_DIR.'/application/views/layout_pages'));
		$mvc_view = Zend_Layout::getMvcInstance()->getView();
		$mvc_view->baseUrl = "";

		try {
			$frontController->dispatch();
		}
		catch(Exception $e)
		{
			echo nl2br($e->__toString());
		}
	}
}
?>
